package com.applet.controller.user;

import com.applet.common.context.BaseContext;
import com.applet.common.vo.Result;
import com.applet.pojo.dto.ActivityStatusDTO;
import com.applet.pojo.dto.AppCreationDTO;
import com.applet.pojo.vo.ActivityItemVO;
import com.applet.pojo.vo.SignActivityDetailVo;
import com.applet.service.ActivityService;
import com.applet.service.AppCreationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: studio-applet
 * @package: com.applet.controller.admin
 * @className: AppUserController
 * @author: Shen Haitao
 * @description: TODO
 * @date: 2024/12/16 21:09
 * @version: 1.0
 */
@RestController
@RequestMapping("/user/activity")
@Slf4j
@Tag(name = "用户相关活动操作接口")
public class UserActivityController {

    @Autowired
    private ActivityService activityService;

    @Autowired
    private AppCreationService creationService;

    @Operation(summary = "获取当前活动的详细信息")
    @GetMapping("getActDetail/{id}")
    public Result<SignActivityDetailVo> getActDetail(@PathVariable String id) {
        log.info("用户查看当前活动的详情" + id);
        SignActivityDetailVo signActivityDetail = activityService.getActDetail(id);
        return Result.success(signActivityDetail);
    }

    @Operation(summary = "保存或更新当前登录用户活动的收藏或报名状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam String id, @RequestBody ActivityStatusDTO statusDTO) {
        log.info("保存用户或更新用户报名或者收藏状态" + statusDTO);
        activityService.updateStatusById(id, statusDTO);
        return Result.success();
    }

    @Operation(summary = "用户保存活动作品")
    @PostMapping("saveWorks")
    public Result saveOrUpload(@RequestParam String id, @RequestBody @Validated AppCreationDTO creationDTO) {

        creationService.saveOrUpload(id, creationDTO);
        return Result.success();
    }

    @Operation(summary = "用户查询已报名的活动(我的活动)")
    @GetMapping("registeredActivities")
    public Result<List<ActivityItemVO>> registeredActivities(){
        String currentUserId = BaseContext.getCurrentId();
        List<ActivityItemVO> registeredActivities = activityService.registeredActivities(currentUserId);
        return Result.success(registeredActivities);
    }

    @Operation(summary = "用户查询已收藏的活动(我的收藏)")
    @GetMapping("collectedActivities")
    public Result<List<ActivityItemVO>> collectedActivities(){
        String currentUserId = BaseContext.getCurrentId();
        List<ActivityItemVO> collectedActivities = activityService.collectedActivities(currentUserId);
        return Result.success(collectedActivities);
    }
}
